<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>系统配置</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" th:href="@{/css/font.css}">
        <link rel="stylesheet" th:href="@{/css/xadmin.css}">
        <link rel="stylesheet" href="../lib/layui/css/layui.css" media="all">
        <script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
        <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
        <script src="../js/jquery.min.js" charset="utf-8"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-card-header">系统配置</div>
                <div class="layui-col-md12">
                    <div class="layui-card" style="padding-bottom: 1px">
                        <div class="layui-card-body ">
                            <div class="layui-form-item">
                                <table class="layui-table" lay-data="{url:'/systemConfig/getConfigType',page:true,limit:5,toolbar: '#toolbarDemo',id:'runningStatus'}" lay-filter="runningStatus">
                                    <thead>
                                        <tr>
                                            <th lay-data="{type:'radio', width:80}">选择</th>
                                            <th lay-data="{field:'configCode', edit: 'text',width:200}">配置类型编码</th>
                                            <th lay-data="{field:'configName', edit: 'text',width:150}">配置类型名称</th>
                                            <th lay-data="{fixed: 'right', width:100, align:'center', toolbar: '#barDemo'}">是否启用</th>
                                        </tr>
                                    </thead>
                                </table>
                            </div>
                            <script type="text/html" id="toolbarDemo">
                                <div class="layui-btn-container">
                                    <button class="layui-btn layui-btn-sm" lay-event="del">删除</button>
                                </div>
                            </script>
                            <script type="text/html" id="barDemo">
                                {{# if(d.isStart==1){ }}
                                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">停用</a>
                                {{# } }}
                                {{# if(d.isStart==0){ }}
                                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">启用</a>
                                {{# } }}
                            </script>
                            <div class="layui-form-item">
                                <table class="layui-table" lay-data="{url:'/systemConfig/filsList',toolbar: '#filsbarDemo',id:'fils'}" lay-filter="fils">
                                    <thead>
                                        <tr>
                                            <th lay-data="{type:'radio', width:80}">选择</th>
                                            <th lay-data="{field:'configValueId', edit: 'text',width:200}">配置参数ID</th>
                                            <th lay-data="{field:'configValueName', edit: 'text',width:200}">配置参数名称</th>
                                        </tr>
                                    </thead>
                                </table>
                            </div>
                            <script type="text/html" id="filsbarDemo">
                                <div class="layui-btn-container">
                                    <button class="layui-btn layui-btn-sm" lay-event="filsDel">删除</button>
                                </div>
                            </script>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script>
            layui.use(['table', 'layer'], function () {
                var table=layui.table;
                //监听配置单元格编辑
                table.on('edit(runningStatus)', function(obj){
                    var data = obj.data //得到所在行所有键值
                    //因为导入数据的时候是按configValueId=1的，所以根据id修改会有bug，建议这个表再加一个configId，然后修改可以根据configId来改
                    layer.confirm('确认修改？',{btn: ['确定', '取消']} ,function(index) {
                        //确定
                        $.ajax({
                            type:"POST",
                            url:'/systemConfig/upDate?id='+data.id+"&configCode="+data.configCode+"&configName="+data.configName,
                            async: false,
                            contentType:'application/json;charset=UTF-8',
                            dataType:'json',
                            success:function(data){
                                if(data){
                                    layer.msg('修改成功');
                                }else{
                                    layer.msg('修改失败');
                                }
                            },
                            error:function () {
                            }
                        });
                    },function () {
                        //取消
                        table.reload("runningStatus");
                    });
                });
                //监听单选按钮
                table.on('radio(runningStatus)',function(){
                    //获取当前选择的配置类型编码   注意：和74行同理，建议这个表再加一个configId
                    var configCode=$(this).parents('tr').find('td').eq(1).text();
                    //参数表导入数据
                    table.reload('fils', {
                        where: {
                            configCode: configCode
                        }
                        , url: '/systemConfig/filsList'
                        , method: 'post'
                    });
                });
                //监听参数单元格编辑
                table.on('edit(fils)', function(obj){
                    var data = obj.data //得到所在行所有键值
                    layer.confirm('确认修改？',{btn: ['确定', '取消']} ,function(index) {
                        //确定
                        $.ajax({
                            type:"POST",
                            url:'/systemConfig/upFils?id='+data.id+"&configValueId="+data.configValueId+"&configValueName="+data.configValueName,
                            async: false,
                            contentType:'application/json;charset=UTF-8',
                            dataType:'json',
                            success:function(data){
                                if(data){
                                    layer.msg('修改成功');
                                }else{
                                    layer.msg('修改失败');
                                }
                            },
                            error:function () {
                            }
                        });
                    },function () {
                        //取消
                        table.reload("fils");
                    });
                });
                //监听配置表单选按钮选中的那一行数据
                table.on('toolbar(runningStatus)', function(obj){
                    var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
                    var data=JSON.stringify(checkStatus.data);  //获取选中行数据json字符串
                    var configCode=data.split('"')[5];   //以双引号分割成数组，获取数组里面的configCode的值
                    layer.confirm('确认删除？', function(index) {
                        $.ajax({
                            type:"POST",
                            url:'/systemConfig/del?configCode='+configCode,
                            async: false,
                            contentType:'application/json;charset=UTF-8',
                            dataType:'json',
                            success:function(data){
                                if(data){
                                    layer.close(index);
                                    layer.msg('删除成功');
                                    table.reload("runningStatus");
                                    table.reload("fils");
                                }else{
                                    layer.msg('删除失败');
                                }
                            },
                            error:function () {
                            }
                        });
                    });
                });
                //监听参数表单选按钮选中的那一行数据
                table.on('toolbar(fils)', function(obj){
                    var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
                    var data=JSON.stringify(checkStatus.data);  //获取选中行数据json字符串
                    var idstr=data.substring(7);  //去除前面7个字符(id的值前面有7个字符)
                    var id=parseInt(idstr.split(',')[0]);   //以逗号分割成数组，获取数组里面的id的值,并且转换成int类型
                    layer.confirm('确认删除？', function(index) {
                        $.ajax({
                            type:"POST",
                            url:'/systemConfig/delFils?id='+id,
                            async: false,
                            contentType:'application/json;charset=UTF-8',
                            dataType:'json',
                            success:function(data){
                                if(data){
                                    layer.close(index);
                                    layer.msg('删除成功');
                                    table.reload("fils");
                                }else{
                                    layer.msg('删除失败');
                                }
                            },
                            error:function () {
                            }
                        });
                    });
                });
                //监听是否启用/停用
                table.on('tool(runningStatus)', function(obj){
                    var data = obj.data;
                    layer.confirm('确认修改启用状态？', function(index){
                        $.ajax({
                            type:"POST",
                            url:'/systemConfig/upIsStart?configCode='+data.configCode+"&isStart="+data.isStart,
                            async: false,
                            contentType:'application/json;charset=UTF-8',
                            dataType:'json',
                            success:function(data){
                                if(data){
                                    layer.close(index);
                                    layer.msg('修改成功');
                                    table.reload("runningStatus");
                                }else{
                                    layer.msg('修改失败');
                                }
                            },
                            error:function () {
                            }
                        });
                    });
                });

            });


        </script>
    </body>
</html>